package net.erl.objects.pattern;

import net.erl.objects.ErlTerm;

import java.util.Map;

/**
 * A pattern that can be matched/applied against an ErlTerm.
 * Usually constructed using an ErlPatternBuilder.
 */
public interface ErlPattern extends EPMatchable {

    /**
     * This is essentially: matchAndSet(term, null).
     * @param term  The term to match against.
     * @return      Null if no match, or a map of bound variables.
     */
    public Map<String, ErlTerm> match(ErlTerm term);


    /**
     * Match against term, return bound vars map or null if no match.
     * initialVars is used as set of prebound values. if null, an empty map is used.
     * The original initialVars is never updated - if new variables are bound, a
     * new map will be allocated.
     * @param term  The term to match against.
     * @param initialVars   Initial variable bindings. If not null, this will be considered
     *                      in the pattern match, and of course added to result.
     * @return      Null if no match, or a map of bound variables.
     */
    public Map<String, ErlTerm> matchAndSet(ErlTerm term, Map<String, ErlTerm> initialVars);

}